
<h2 style='text-align:center'>商品审核</h2>
<div id='MainGoods_GoodsListArea'>
	<div style='display:flex'>
		<div style='flex:1'>
			<input type="text" id='MainGoods_SearchInp' style='width:100%' />
		</div>
		<div>
			<button type='button' id='MainGoods_SearchBtn'>搜索</button>
		</div>
	</div>
	<select id="MainGoods_TypeSelect" style='width:100%'>
		<option value="7">全部</option>
		<option value="1">待审核</option>
		<option value="2">正常</option>
		<option value="3">未通过</option>
		<option value="4">已封禁</option>
	</select>


	<!--商品列表-->
	<div id='MainGoods_GoodsList'></div>


	<!--分页-->
	<div id='MainGoods_GoodsFpage' style='text-align:center;margin:20px auto'></div>

	<div>
		<button id='MainGoods_Back'>返回商户管理</button>
		<button id='MainGoods_Refresh'>刷新数据</button>
	</div>
</div>


<!--商品详情-->
<div id='MainGoods_GoodsDetail'></div>

<script>
var MainGoods_Pnow = 1;	//当前页
var MainGoods_Max = ''; //最大页
var detail_id = ''; 	//指定的商品详情id


	
MainGoods_GetGoodsList();	//获取商品列表


$('#MainGoods_SearchBtn').click(function(){
	Clear_MainGoodsPnowOrMax(); 	//重置商品列表面的当前页和最大页的值
	MainGoods_GetGoodsList();	//获取商品列表
});

//刷新数据
$('#MainGoods_Refresh').click(function(){
	MainGoods_GetGoodsList();
});


//切换商品状态
$('#MainGoods_TypeSelect').change(function(){
	Clear_MainGoodsPnowOrMax(); 	//重置商品列表面的当前页和最大页的值
	MainGoods_GetGoodsList();	//获取商品列表
});



$('#MainGoods_Back').click(function(){
	$('#Main_Nav').val('Main_Store');
	CacheSelectVal_Load();	//缓存导航值并加载相应页
});


//获取商品列表
function MainGoods_GetGoodsList(){
	//判断是否为商户页跳转而来
	if(sessionStorage.StoreToGoodsList_Id){
		$('#MainGoods_Back').show();
	}else{
		$('#MainGoods_Back').hide();
	}


	var type_sel = $('#MainGoods_TypeSelect').find('option:selected').val();
	var search = ChangeChar($('#MainGoods_SearchInp').val().trim());
	var data = {
		type:'GetGoodsList',
		pnow:MainGoods_Pnow,
		type_sel:type_sel,
		search:search,
		psize:5,
		store_id:parseInt(sessionStorage.StoreToGoodsList_Id)
	};

	sca(data,function(res){
		MainGoods_GetGoodsListParse(res);
	},after_url);

}

//解析列表
function MainGoods_GetGoodsListParse(res){
	if(/^\[{"id":.*$/.test(res)){
		var tmp_data = JSON.parse(res);
		var tmp_str = '';
		for(var i=0;i<tmp_data.length;i++){
			tmp_str += "<div style='margin:5px 0;border:1px solid;word-break:break-all;font-size:14px;color:#777;padding:5px'>";
			tmp_str += "商品标题："+ChangeChar(tmp_data[i].title,2);
			tmp_str += "　"+tmp_data[i].price+'元';
			switch(tmp_data[i].goods_stat){
				case '1':var stat_str2 = '待审';break;
				case '2':case '5':var stat_str2 = '<span style="color:blue">正常</span>';break;
				case '3':var stat_str2 = '未通过';break;
				case '4':var stat_str2 = '已封禁';break;
			}
			tmp_str +="<br><span style='text-align:right'>状态："+stat_str2+"　<button  onclick=MainGoods_GoodsDetail("+tmp_data[i].id+")>查看</button></span>";

			tmp_str +="<div style='text-align:right'><button onclick=MainGoods_ChangeGoodsStat("+tmp_data[i].id+",2)>通过</button><button onclick=MainGoods_ChangeGoodsStat("+tmp_data[i].id+",3)>未通过</button><button onclick=MainGoods_ChangeGoodsStat("+tmp_data[i].id+",4)>封禁</button><button onclick=MainGoods_ChangeGoodsStat("+tmp_data[i].id+",1)>解封</button></div>";

			tmp_str += "<div style='clear:both'></div></div>";
		}
		$('#MainGoods_GoodsList').html(tmp_str);

		var max_page = MainGoods_Max?MainGoods_Max:MainGoods_Pnow+1;
		Fpage(MainGoods_Pnow,max_page,function(p){
			MainGoods_Pnow = p;
			MainGoods_GetGoodsList();
		},1,1,'#MainGoods_GoodsFpage');
	}else{
		if(MainGoods_Pnow == 1){
			$('#MainGoods_GoodsList').html('');
		}
		MainGoods_Max = MainGoods_Pnow-1;
		Fpage(MainGoods_Pnow-1,MainGoods_Max,function(p){
			MainGoods_Pnow = p;
			MainGoods_GetGoodsList();
		},1,1,'#MainGoods_GoodsFpage');
	}
}


//查看商品详情
function MainGoods_GoodsDetail(id){
	detail_id = id;
	$('#MainGoods_GoodsListArea').hide();
	Ajax('',function(res){
		$('#MainGoods_GoodsDetail').html(res).show();
	},'Template/Main_Goods_GoodsDetail.html');
}



//修改商品状态
function MainGoods_ChangeGoodsStat(id,stat){
	Notice('处理中......');
	var data = {
		type:'ChangeGoodsStat',
		id:id,
		stat:stat
	}
	Ajax2(data,function(res){
		C(res);
		Notice();

		if(res == 'ok'){
			A('操作成功！');
			MainGoods_GetGoodsList();	//获取商品列表
		}else{
			A('操作异常2！');
		}
	},after_url);

}

</script>